package com.ymatou.iapi.fastturnover.testcase;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.fastturnover.parameter.getChangeHisBean;
import com.ymatou.iapi.fastturnover.service.getChangeHisCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.fastturnover.account_config_log;
import com.ymttest.database.model.fastturnover.account_config_logExample;
import com.ymttest.database.sqlwapper.fastturnover.account_config_logWrapper;
import com.ymttest.utils.EnvSetup;
/**
*操作历史
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getChangeHis{
	private static getChangeHisBean bean;
	private static getChangeHisCall call;
	
	SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
	Long fastturnover_seller=Long.parseLong(EnvSetup.getData("fastturnover_seller"));
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("操作历史");
	}

	@Before
	public void caseUp() {
		bean=new getChangeHisBean();
		call=new getChangeHisCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getChangeHis_001() {
		Logger.start(true,"查询配置");
		try {
			
			bean.setSellerId(fastturnover_seller);
			call.setData(bean);
			call.callService();	
			
			
			account_config_logExample example=new account_config_logExample();
			example.createCriteria().andSeller_idEqualTo(bean.getSellerId());
			example.setOrderByClause(" add_time desc");
			
			account_config_logWrapper logWapper=new account_config_logWrapper();
			List<account_config_log> logs=logWapper.selectByExample(example);
			
			Logger.verifyEquals("200", call.getCode1(), "验证code");
			Logger.verifyEquals(call.getResult().length(), logs.size(), "验证数量");
			
			for(int i=0;i<logs.size();i++)
			{
				Logger.verifyEquals(call.getResult().getJSONObject(i).getInt("actionType"), logs.get(i).getAction_type(), "验证actionType");
				Logger.verifyEquals(call.getResult().getJSONObject(i).getString("rate"), logs.get(i).getRate()==null?"null":logs.get(i).getRate().toString(), "验证Rate");
				Logger.verifyEquals(call.getResult().getJSONObject(i).getString("maxLoan"), logs.get(i).getMax_loan()==null?"null":logs.get(i).getMax_loan().toString(), "验证maxLoan");
				Logger.verifyEquals(call.getResult().getJSONObject(i).getString("operator"), logs.get(i).getOperator(), "验证Operator");
				
				if(logs.get(i).getStart_time()!=null)
				{
				   Logger.verifyEquals(call.getResult().getJSONObject(i).getString("startTime").replace("T", " "), formatter.format(logs.get(i).getStart_time()), "验证startTime");
				}
				if(logs.get(i).getEnd_time()!=null)
				{
				    Logger.verifyEquals(call.getResult().getJSONObject(i).getString("endTime").replace("T", " "), formatter.format(logs.get(i).getEnd_time()), "验证endTime");
				}
				Logger.verifyEquals(call.getResult().getJSONObject(i).getString("addTime").replace("T", " "), formatter.format(logs.get(i).getAdd_time()), "验证addTime");
				
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getChangeHis_002() {
		Logger.start(true,"查询配置-seller_id为空");
		try {
			
			//bean.setSellerId(fastturnover_seller);
			call.setData(bean);
			call.callService();	

			Logger.verifyEquals("400", call.getCode1(), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}